package cn.edu.hqu.cst.crj.mediashowdemo3;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import java.io.File;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    EditText edt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //返回
        findViewById(R.id.btn_back).setOnClickListener(this);
        //查询
        findViewById(R.id.btn1).setOnClickListener(this);
        //提取编辑框文字
        edt=findViewById(R.id.editText);

        /*requestAllPower();


        VideoView videoview = (VideoView)findViewById(R.id.videoView);

        videoview.setMediaController(new MediaController(this));

        videoview.setVideoPath("/sdcard/DCIM/one.mp4");//(文件名根据实际情况修改)

        videoview.start();*/
    }



    @Override
    public void onClick(View v) {
        String str=edt.getText().toString().trim();
        Intent intent=new Intent();
        switch (v.getId()) {
            case R.id.btn1:

                //showMsg(str);
               // intent.setClass(MainActivity.this, play.class);
                // intent.putExtra("path",str);
                //startActivity(intent);
                if(fileIsExists(str)){
                    intent.setClass(MainActivity.this, play.class);
                    intent.putExtra("path",str);
                    startActivity(intent);
                }
                break;

            case R.id.btn_back:
                finish();
        }
    }

    //显示信息
    private  void  showMsg(String msg){
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
    }

    public boolean fileIsExists(String strFile)
    {
        try
        {
            File f=new File(strFile);
            if(!f.exists())
            {
                showMsg("文件不存在，请重新输入");
                return false;
            }
            else{
                showMsg("test2");
                return true;
            }

        }
        catch (Exception e)
        {
            return false;
        }
    }


}
